Centralize handleError and rename pages api→endpoints - #285
Conversation
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (21)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
📝 WalkthroughWalkthrough本次变更将前端 HTTP 请求迁移到按功能划分的 ChangesHTTP 端点重组
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 155 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Actionable comments posted: 12
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/public/pages/scripts/endpoints/base.mjs`:
- Around line 6-11: 统一 JSON 响应处理:将 finishAuthenticatedJsonMutation 重命名为通用 JSON
响应 helper,并在其中直接抛出构造的错误而非返回 Promise.reject;将 base.mjs 中
24-25、42-43、58-59、71-72、81-82、106-107 和 200-202 行所有重复 JSON 解析与错误处理改为调用该共享
helper,删除重复逻辑。
- Around line 32-34: Update hosturl_in_local_ip to use async/await exclusively:
await ping(true), return data.hosturl_in_local_ip on success, and preserve
window.location.origin as the fallback when ping fails.
In `@src/public/pages/scripts/endpoints/p2p/evfsMedia.mjs`:
- Around line 7-10: 为 evfsMedia.mjs 中导出 entityFileUrl 和 mediaRefUrl 的 re-export
添加一行有意义的中文 JSDoc 摘要,替换当前空的 JSDoc stub,并保持现有导出内容不变。
In `@src/public/pages/scripts/endpoints/parts.mjs`:
- Around line 200-205: Update unlockAchievement to be async, await the unlock
fetch, and treat non-successful responses as failures; route network and
response errors through the existing centralized handleError helper instead of
silently swallowing them, while preserving the current request payload and
endpoint.
In `@src/public/pages/scripts/endpoints/registries.mjs`:
- Around line 18-27: Update the registry fetch flow around fetchPromise and
registryFetchCache so a rejected request removes its cache entry, but only when
the entry still references that same Promise. Keep successful responses cached
as before and preserve nocache behavior, allowing later calls to retry after
transient failures.
In `@src/public/pages/scripts/features/errorHandlers.mjs`:
- Around line 28-42: Update the direct-processing condition in handleError so it
checks whether the error argument was provided, rather than relying on
truthiness. Immediately process empty strings, 0, false, and other explicitly
supplied values while preserving callback-return behavior when error is omitted.
- Around line 14-17: 简化两个 toError 实现,移除对 error.message 的包装对象类型检查;在
src/public/pages/scripts/features/errorHandlers.mjs:14-17 和
src/scripts/errorHandlers.mjs:13-16 中,保留 Error 实例直接返回,并直接优先使用 error.message 构造新的
Error,否则回退到 String(error)。
In `@src/public/parts/shells/AGENTS.md`:
- Around line 19-20: Update the documented Shell API path in the
frontend/backend endpoint guidance to remove the erroneous backslash before the
colon, changing `/api/parts/shells\:<name>/...` to
`/api/parts/shells:<name>/...` while leaving the surrounding routing guidance
unchanged.
In `@src/public/parts/shells/cabinet/public/src/endpoints.mjs`:
- Around line 62-69: Update cabinetRequest so unlock option presence is
determined by an own-property check rather than comparing its value with
undefined; use the provided opts.unlock value, including explicit undefined,
when the property exists, and fall back to currentUnlockToken() only when unlock
is omitted. Preserve the existing behavior of unlockCabinet() and
finalizeDelete() wrappers.
In `@src/public/parts/shells/cabinet/public/src/recoveryHistory.mjs`:
- Line 22: Replace the mixed Promise-chain handling in the recovery flow with a
try/catch around the awaited finalizeDelete call, invoking the existing
handleError('cabinet.bootstrapFailed') callback from the catch block while
preserving the current recoveryToken and cabinetId arguments.
- Around line 112-117: 更新 makePatchHistory 和 makeMoveHistory,在创建历史项并推入时捕获 unlock
token;随后 undo 和 redo 中的每次 patchEntry 调用都使用该固定 token,并与 cabinetId 一起传入,禁止重新解析
currentUnlockToken()。
In `@src/scripts/checks/i18n_refs.mjs`:
- Line 171: 更新 src/scripts/checks/i18n_refs.mjs:171 附近的 handleError 规则及
extractI18nRefsFromSource(),仅对从前端 features/errorHandlers.mjs 导出的 factory 形式扫描首参数
i18n key,避免将后端 fount/scripts/errorHandlers.mjs 的 handleError(error,
...extras)误判为 key;同步补充前端 factory 与后端 string error 的测试覆盖。更新
src/scripts/checks/AGENTS.md:39 的规则说明,使其反映按导入来源识别 handleError 的行为。
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 3307e741-8d95-4d03-a38c-5e6680ff558d
⛔ Files ignored due to path filters (2)
src/public/pages/scripts/endpoints/desktop.iniis excluded by!**/desktop.inisrc/public/pages/scripts/endpoints/p2p/desktop.iniis excluded by!**/desktop.ini
📒 Files selected for processing (59)
src/public/pages/AGENTS.mdsrc/public/pages/base.mjssrc/public/pages/index.htmlsrc/public/pages/log_viewer/index.mjssrc/public/pages/login/index.mjssrc/public/pages/protocolhandler/index.mjssrc/public/pages/scripts/api/p2p/evfsMedia.mjssrc/public/pages/scripts/components/partpath_picker.mjssrc/public/pages/scripts/endpoints/base.mjssrc/public/pages/scripts/endpoints/p2p/evfsMedia.mjssrc/public/pages/scripts/endpoints/parts.mjssrc/public/pages/scripts/endpoints/registries.mjssrc/public/pages/scripts/endpoints/server_events.mjssrc/public/pages/scripts/features/emoji/providers.mjssrc/public/pages/scripts/features/errorHandlers.mjssrc/public/pages/scripts/features/markdown/extensions.mjssrc/public/pages/scripts/host/credentialManager.mjssrc/public/pages/scripts/i18n/base.mjssrc/public/parts/shells/AGENTS.mdsrc/public/parts/shells/access/public/index.mjssrc/public/parts/shells/achievements/public/index.mjssrc/public/parts/shells/browserIntegration/src/endpoints.mjssrc/public/parts/shells/cabinet/AGENTS.mdsrc/public/parts/shells/cabinet/public/src/api.mjssrc/public/parts/shells/cabinet/public/src/endpoints.mjssrc/public/parts/shells/cabinet/public/src/entryActions.mjssrc/public/parts/shells/cabinet/public/src/navigation.mjssrc/public/parts/shells/cabinet/public/src/properties.mjssrc/public/parts/shells/cabinet/public/src/recoveryHistory.mjssrc/public/parts/shells/cabinet/public/src/wiring.mjssrc/public/parts/shells/cabinet/src/cabinets.mjssrc/public/parts/shells/config/public/index.mjssrc/public/parts/shells/debug_info/public/index.mjssrc/public/parts/shells/deskpet/public/index.mjssrc/public/parts/shells/discordbot/public/index.mjssrc/public/parts/shells/home/public/src/data.mjssrc/public/parts/shells/home/public/src/events.mjssrc/public/parts/shells/home/public/src/home.mjssrc/public/parts/shells/home/public/src/ui.mjssrc/public/parts/shells/ideIntegration/public/index.mjssrc/public/parts/shells/install/public/uninstall/index.mjssrc/public/parts/shells/proxy/public/index.mjssrc/public/parts/shells/serviceSourceManage/public/index.mjssrc/public/parts/shells/subfounts/public/subfount.mjssrc/public/parts/shells/subfounts/test/integration/helpers/subfount_client_worker.mjssrc/public/parts/shells/telegrambot/public/index.mjssrc/public/parts/shells/themeManage/public/index.mjssrc/public/parts/shells/tutorial/public/index.mjssrc/public/parts/shells/userSettings/public/index.mjssrc/public/parts/shells/wechatbot/public/index.mjssrc/scripts/checks/AGENTS.mdsrc/scripts/checks/i18n_refs.mjssrc/scripts/errorHandlers.mjssrc/scripts/sentry_state.mjssrc/scripts/test/hub/apis/health.mjssrc/scripts/test/playwright/pages_server.mjssrc/server/test/manifest.jsonsrc/server/web_server/endpoints.mjssrc/server/web_server/p2p_endpoints.mjs
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
steve02081504/fount-p2p(manual)
💤 Files with no reviewable changes (3)
- src/public/pages/scripts/api/p2p/evfsMedia.mjs
- src/public/parts/shells/cabinet/public/src/api.mjs
- src/server/web_server/p2p_endpoints.mjs
There was a problem hiding this comment.
Actionable comments posted: 6
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/public/locales/ar-SA.json`:
- Line 5484: Replace the Simplified Chinese unlock_failed text with the correct
locale-specific translations while preserving the ${error} placeholder: update
src/public/locales/ar-SA.json at lines 5484-5484 with Arabic,
src/public/locales/uk-UA.json at lines 5484-5484 with Ukrainian,
src/public/locales/vi-VN.json at lines 5484-5484 with Vietnamese, and
src/public/locales/zh-TW.json at lines 5483-5483 with Traditional Chinese such
as “解鎖成就失敗:${error}”.
In `@src/public/locales/en-UK.json`:
- Line 5481: Update the achievements.error.unlock_failed translation in
src/public/locales/en-UK.json:5481-5481,
src/public/locales/de-DE.json:5484-5484,
src/public/locales/emoji.json:5484-5484,
src/public/locales/es-ES.json:5484-5484,
src/public/locales/fr-FR.json:5484-5484,
src/public/locales/hi-IN.json:5484-5484,
src/public/locales/is-IS.json:5484-5484, and
src/public/locales/it-IT.json:5484-5484 with natural English, German, emoji,
Spanish, French, Hindi, Icelandic, and Italian text respectively. Preserve the
${error} placeholder in every locale and do not leave Chinese text in any
translation.
In `@src/public/locales/ja-JP.json`:
- Line 5484: Translate the unlock_failed entry in
src/public/locales/ja-JP.json#L5484-L5484 into Japanese,
src/public/locales/ko-KR.json#L5484-L5484 into Korean,
src/public/locales/lzh.json#L5484-L5484 into appropriate traditional Classical
Chinese, src/public/locales/nl-NL.json#L5484-L5484 into Dutch,
src/public/locales/pt-PT.json#L5484-L5484 into Portuguese, and
src/public/locales/ru-RU.json#L5484-L5484 into Russian; preserve the ${error}
placeholder in every translation.
In `@src/public/locales/ru-RU.json`:
- Line 5483: Remove the stray backtick from the user-facing load_failed
translation in ru-RU.json so the achievement loading error message displays
without an extra backtick.
In `@src/public/pages/scripts/endpoints/base.mjs`:
- Around line 8-9: Replace the Promise catch in the response parsing flow at
src/public/pages/scripts/endpoints/base.mjs:8-9 with try/catch around await
response.json(), preserving the empty-object fallback for non-JSON bodies. In
the fetchPromise handling at
src/public/pages/scripts/endpoints/registries.mjs:28-31, use try { await
fetchPromise } catch (error) to remove the current cache entry and rethrow the
original error.
- Around line 33-34: Remove the single-use temporary bindings in the relevant
endpoint flow: inline the awaited `ping(true)` result directly into the return
expression instead of assigning it to `data`, and inline the `value` expression
at the return site around the corresponding line 200 logic. Preserve the
existing returned properties and behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 4834cf6f-342c-4ae1-889d-a5ca567740f7
📒 Files selected for processing (42)
src/decl/locale_data.tssrc/public/locales/ar-SA.jsonsrc/public/locales/de-DE.jsonsrc/public/locales/emoji.jsonsrc/public/locales/en-UK.jsonsrc/public/locales/es-ES.jsonsrc/public/locales/fr-FR.jsonsrc/public/locales/hi-IN.jsonsrc/public/locales/is-IS.jsonsrc/public/locales/it-IT.jsonsrc/public/locales/ja-JP.jsonsrc/public/locales/ko-KR.jsonsrc/public/locales/lzh.jsonsrc/public/locales/nl-NL.jsonsrc/public/locales/pt-PT.jsonsrc/public/locales/ru-RU.jsonsrc/public/locales/uk-UA.jsonsrc/public/locales/vi-VN.jsonsrc/public/locales/zh-CN.jsonsrc/public/locales/zh-TW.jsonsrc/public/pages/scripts/endpoints/base.mjssrc/public/pages/scripts/endpoints/p2p/evfsMedia.mjssrc/public/pages/scripts/endpoints/parts.mjssrc/public/pages/scripts/endpoints/registries.mjssrc/public/pages/scripts/features/errorHandlers.mjssrc/public/parts/shells/AGENTS.mdsrc/public/parts/shells/cabinet/public/src/endpoints.mjssrc/public/parts/shells/cabinet/public/src/recoveryHistory.mjssrc/public/parts/shells/chat/public/hub/chatConfig.mjssrc/public/parts/shells/chat/public/hub/friendsList.mjssrc/public/parts/shells/chat/public/hub/groupContextMenu.mjssrc/public/parts/shells/chat/public/hub/profileEdit.mjssrc/public/parts/shells/chat/public/hub/wiring/bootstrap.mjssrc/public/parts/shells/chat/public/profile/index.mjssrc/public/parts/shells/chat/public/src/achievements.mjssrc/public/parts/shells/chat/test/manifest.jsonsrc/public/parts/shells/social/public/src/init.mjssrc/public/parts/shells/social/test/manifest.jsonsrc/scripts/checks/AGENTS.mdsrc/scripts/checks/i18n_refs.mjssrc/scripts/checks/test/i18n_refs.test.mjssrc/scripts/errorHandlers.mjs
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
steve02081504/fount-p2p(manual)
542d8b6 to
fe0eca4
Compare
Summary
handleErrorhelpers (toast/console/Sentry)scripts/apiclients toscripts/endpoints(incl. EVFS media client)Test plan
scripts/api/fount test --no-parallelselectors covering pages/cabinet if available改动
集中前后端
handleError,统一日志、Toast 和 Sentry 处理。将页面 API 模块从scripts/api重组为scripts/endpoints,并迁移 EVFS 媒体接口。Cabinet 改用专用端点函数,统一请求、错误和响应解析。同步更新测试路径、国际化文案及少量服务端代码。原因
明确 HTTP 请求边界。减少重复请求逻辑。避免旧
scripts/api引用继续扩散。当前残留的/api/均为实际 HTTP 路径,不是旧模块引用。架构与审美风险
方向正确,但 Cabinet 端点模块约 254 行,认证、请求封装和业务操作仍集中,职责偏重。前后端
handleError仅共享命名,接口和行为仍然分裂。错误处理由静默忽略改为统一上报,可能增加 Sentry 噪声。EVFS 旧重导出已删除,模块边界更清晰,但调用方路径耦合更强。